<?php

namespace App\FrontModule\Presenters;

use \App\Component\Shortnew as ShortnewComponent,
    \App\Model\Dao\Shortnew;

/**
 * Homepage presenter
 * @author jirka
 */
class HomepagePresenter extends BasePresenter {
  
  /** @var \App\Model\UserManager @inject */
  public $um;
  
  /**
   * Action for activation code
   * @param String $code
   */
  public function actionActivation($code){
    if(!isset($code)){
      $this->redirect('Homepage:default');
    }
    
    $res = $this->um->activateUser($code);
    
    if($res){
      $this->flashMessage('Váš účet je aktivní, můžete se přihlásit', 'success');
    }else{
      $this->flashMessage('Ups, něco se nepovedlo... v případě problémů nás kontaktujte emailem', 'danger');
    }
    
    $this->redirect('Homepage:default');
  }
  
  /**
   * Create component short new
   * @param String $name
   * @return ShotnewComponent
   */
  public function createComponentShortNew($name){
    $shortnew = new ShortnewComponent();
    return $shortnew->init($this->em->getDao(Shortnew::getClassName())->findBy(array(), array('id' => 'desc')), 5);
  }
}
